export const filters = {
    state: {
        cityFilter: '',
        textSearch: '',
        activeLocationFilter: 'all',
        onlyLiked: false,
        brewMethodsFilter: [],
        hasMatcha: false,
        hasTea: false,
        hasSubscription: false,
        orderBy: 'name',
        orderDirection: 'asc',
    },
    actions: {
        updateCityFilter({commit}, data) {
            commit('setCityFilter', data.cityFilter);
        },
        updateTextSearch({commit}, data) {
            commit('setTextSearch', data.textSearch);
        },
        updateActiveLocationFilter({commit}, data) {
            commit('setActiveLocationFilter', data.activeLocationFilter);
        },
        updateOnlyLiked({commit}, data) {
            commit('setOnlyLiked', data.onlyLiked);
        },
        updateBrewMethodsFilter({commit}, data) {
            commit('setBrewMethodsFilter', data.brewMethodsFilter);
        },
        updateHasMatcha({commit}, data) {
            commit('setHasMatcha', data.hasMatcha);
        },
        updateHasTea({commit}, data) {
            commit('setHasTea', data.hasTea);
        },
        updateHasSubscription({commit}, data) {
            commit('setHasSubscription', data.hasSubscription);
        },
        updateOrderBy({commit}, data) {
            commit('setOrderBy', data.orderBy);
        },
        updateOrderDirection({commit}, data) {
            commit('setOrderDirection', data.orderDirection);
        },
        resetFilters({commit},data){
            commit('resetFilters');
        }
    },
    mutations: {
        //设置城市筛选条件
        setCityFilter(state, cityFilter) {
            state.cityFilter = cityFilter;
        },
        setTextSearch(state, textSearch) {
            state.textSearch = textSearch;
        },
        setActiveLocationFilter(state, activeLocationFilter) {
            state.activeLocationFilter = activeLocationFilter;
        },
        setOnlyLiked(state, onlyLiked) {
            state.onlyLiked = onlyLiked;
        },
        setBrewMethodsFilter(state, brewMethodsFilter) {
            state.brewMethodsFilter = brewMethodsFilter;
        },
        setHasMatcha(state, hasMatcha) {
            state.hasMatcha = hasMatcha;
        },
        setHasTea(state, hasTea) {
            state.hasTea = hasTea;
        },
        setHasSubscription(state, hasSubscription) {
            state.hasSubscription = hasSubscription;
        },
        setOrderBy(state, orderBy) {
            state.orderBy = orderBy;
        },
        setOrderDirection(state, orderDirection) {
            state.orderDirection = orderDirection;
        },
        //重置筛选条件
        resetFilters(state) {
            state.cityFilter = '';
            state.textSearch = '';
            state.activeLocationFilter = 'all';
            state.onlyLiked = false;
            state.brewMethodsFilter = [];
            state.hasMatcha = false;
            state.hasTea = false;
            state.hasSubscription = false;
            state.orderBy = 'name';
            state.orderDirection = 'asc';
        },
    },
    getters: {
        getCityFilter(state) {
            return state.cityFilter;
        },
        getTextSearch(state) {
            return state.textSearch;
        },
        getActiveLocationFilter(state) {
            return state.activeLocationFilter;
        },
        getOnlyLiked(state) {
            return state.onlyLiked;
        },
        getBrewMethodsFilter(state) {
            return state.brewMethodsFilter;
        },
        getHasMatcha(state) {
            return state.hasMatcha;
        },
        getHasTea(state) {
            return state.hasTea;
        },
        getHasSubscription(state) {
            return state.hasSubscription;
        },
        getOrderBy(state) {
            return state.orderBy;
        },
        getOrderDirection(state) {
            return state.orderDirection;
        }
    }

};
